<template>
    <Card>
        <p slot="title">流转记录</p>
        <Table :columns="columns1" :data="pageList1.data"></Table>
    </Card>
</template>

<script>
export default {
  name: 'circulation-log-form',
  components: {

  },
  data () {
    return {
      baseUrl: this.$appContext.marvels_core_approve,
      $ajax: null,
      columns1: [
        {
          align: 'center',
          title: '流程阶段',
          key: 'nodeName'
        },
        {
          align: 'center',
          title: '开始时间',
          key: 'startTime',
          render: (h, params) => {
            var vm = this
            return h('span', {}, vm.$util.formatTime(params.row.startTime))
          }
        },
        {
          align: 'center',
          title: '结束时间',
          key: 'endTime',
          render: (h, params) => {
            var vm = this
            return h('span', {}, vm.$util.formatTime(params.row.endTime))
          }
        },
        {
          align: 'center',
          title: '停留时长',
          key: 'castTime',
          render: (h, params) => {
            var vm = this
            return h('span', {}, vm.getCastTime(params))
          }
        },
        {
          align: 'center',
          title: '实际处理人',
          key: 'assigneeName'
        },
        {
          align: 'center',
          title: '审批意见',
          key: 'opinionContent'
        }
      ],
      pageList1: {
        data: [],
        dataTotal: 0,
        pageTotal: 1,
        pageNo: 1,
        pageSize: 50
      }
    }
  },
  methods: {
    init () {
      var vm = this
      var url = this.baseUrl + 'approve/process/task_process/service/getLoanApplyCaseLogs/' + this.taskParams.curLoanId
      this.$ajax.get(url).then(re => {
        var data = re.data
        var code = data.code
        var message = data.message
        if (code !== 'success') {
          this.$Message.warning(message)
          return
        }
        vm.pageList1.data = data.data
      }).catch(er => {

      })
    },
    // 计算停留时长
    getCastTime (params) {
      var endTime = params.row.endTime
      if (!endTime) {
        return ''
      }
      var startTime = params.row.startTime
      if (!startTime) {
        return ''
      }
      var sec = (endTime - startTime) / 1000
      return this.$util.sec2Time(sec)
    },
    // 渲染审批意见
    renderOpinions (params) {
      var opinionList = params.row.opinionList
      var strOpinions = []
      if (opinionList && opinionList.length > 0) {
        for (var i in opinionList) {
          strOpinions.push(opinionList[i].opinionTypeName)
        }
      }
      return strOpinions.join('; ')
    }
  },
  computed: {

  },
  mounted () {

  },
  created () {
    this.$ajax = this.$util.ajax()
  },
  watch: {
    'taskParams.circulationLog' (v) {
      if (v) {
        this.init()
      }
    }
  },
  props: {
    taskParams: Object
  }
}
</script>
